import java.util.Comparator;
import java.util.PriorityQueue;

class IntCmp implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
public class Test {
    //k个最小的值
    //用一个k大小的大根堆，每次都拿堆顶元素与后续的数组的数进行比较，
    // 只要数比堆顶元素大，就将堆顶元素poll，再offer一个新的数到堆中，最后剩下的堆中k个数就是所求值
    public int[] smallestK(int[] arr,int k){
        int[] ret = new int[k];
        if (arr == null || k == 0){
            return ret;
        }
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(k,new IntCmp());

        //k*logK
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }

        //(n-k)*logk
        for (int i = k; i < arr.length; i++) {
            int peekVal = priorityQueue.peek();
            if (arr[i] < peekVal){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }

        for (int i = 0; i < k; i++) {
            ret[i] = priorityQueue.poll();
        }
        return ret;
    }

    public int[] smallestK1(int[] arr,int k){
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();

        //O(N*logN)
        for (int i = 0; i < arr.length; i++) {
            priorityQueue.offer(arr[i]);
        }
        //O(K*logN)
        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = priorityQueue.poll();
        }
        return ret;
    }




    public static void main(String[] args) {
        //Queue<Integer> priorityQueue = new PriorityQueue<>();

        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new IntCmp());
        priorityQueue.offer(11);
        priorityQueue.offer(12);
        System.out.println(priorityQueue.peek());

        /*PriorityQueue<Student> priorityQueue2 = new PriorityQueue<>();
        priorityQueue2.offer(new Student());*/
    }

}
